<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\FourMedicalCheck;
use App\Models\FourAdminTitle;
use App\Models\FourCampus;
use App\Models\FourCheckType;
use App\Models\FourDepartment;
use App\Models\FourItem;
use App\Models\FourLabel;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Tab;

class FourMedicalCheckController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {

        $tab=new Tab();
        $content=Grid::make(FourMedicalCheck::with(['type','campus','item']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('package_name','套餐名称');
            $grid->column('package_pic','套餐图片')->image([],80,80);
            $grid->column('type.type_name','套餐类型');
            $grid->column('campus.campus_name','适用院区');
            $grid->column('item.item_name','套餐项目');
            $grid->column('price','套餐价格');
            //
            $grid->column('status', '状态')->display(function ($released) {
                return $released ? '是' : '否';
            });
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->quickSearch('package_name')->placeholder('搜索...');
        });
        $two=Grid::make(FourItem::with(['check']), function (Grid $grid) {
            $grid->column('id', '项目ID')->sortable();
            $grid->column('item_name', '项目名称');
            $grid->column('item_price', '项目价格');
            $grid->column('check.package_name', '所属套餐');
            $grid->column('item_intro', '项目介绍');
            $grid->column('note', '注意事项');
            //
            $grid->column('status', '项目状态')->display(function ($released) {
                return $released ? '是' : '否';
            });
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->quickSearch('package_name')->placeholder('搜索...');
        });
        $three=Grid::make(FourCheckType::with(['package']), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('type_name','类型名称');
            $grid->column('type_namber','类型数量');
            $grid->column('package.package_name','包含套餐');
            $grid->column('status', '状态')->display(function ($released) {
                return $released ? '是' : '否';
            });
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();
            $grid->quickSearch('package_name')->placeholder('搜索...');
        });
        $tab->add('体检套餐',$content);
        $tab->add('体检项目',$two);
        $tab->add('套餐类型',$three);
        return $tab;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new FourMedicalCheck(), function (Show $show) {
            $show->field('id');
            $show->field('package_name');
            $show->field('package_pic');
            $show->field('package_type');
            $show->field('campus_id');
            $show->field('price');
            $show->field('item');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $tab=new Tab();
        $content=Form::make(new FourMedicalCheck(), function (Form $form) {
            $form->display('id');
            $form->text('name','套餐名称');
            $form->image('avatar','头像');
            $form->select('type_id','套餐类型')->options(FourCheckType::pluck('type_name','id'));
            $form->select('campus_id','院区')->options(FourCampus::pluck('campus_name','id'));
            $form->select('item_id','套餐项目')->options(FourItem::pluck('item_name','id'));
            $form->number('price','套餐价格');
            $form->textarea('package_intro','套餐介绍');
            $form->textarea('note','注意事项');
            // 添加开关操作
            $form->switch('status', '状态');

            $form->display('created_at');
            $form->display('updated_at');
        });
        $two=Form::make(new FourItem(), function (Form $form) {
            $form->display('id');
            $form->text('item_name','项目名称');
            $form->select('medical_check_id','所属套餐')->options(\App\Models\FourMedicalCheck::pluck('package_name','id'));
            $form->number('item_price','项目价格');
            $form->textarea('item_intro','项目介绍');
            $form->textarea('note','注意事项');
            // 添加开关操作
            $form->switch('item_status', '状态');

            $form->display('created_at');
            $form->display('updated_at');
        });
        $three=Form::make(new FourCheckType(), function (Form $form) {
            $form->display('id');
            $form->text('name','类型名称');
            $form->number('type_namber','所包含套餐数量');
            $form->select('medical_check_id','包含套餐')->options(\App\Models\FourMedicalCheck::pluck('package_name','id'));
            // 添加开关操作
            $form->textarea('desc','描述');
            // 添加开关操作
            $form->switch('status', '状态');
            $form->display('created_at');
            $form->display('updated_at');
        });
        $tab->add('体检套餐',$content);
        $tab->add('体检项目',$two);
        $tab->add('套餐类型',$three);
        return $tab;
    }
}
